home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7150 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Who's dumb: Summary
  5. Date: Sat, 17 Feb 96 23:06:59 GMT
  6. Organization: none
  7. Message-ID: <824598419snz@genesis.demon.co.uk>
  8. References: <4fv61e$mho@micky.ibh-dd.de>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4fv61e$mho@micky.ibh-dd.de> beck@duck.ibh-dd.de "Andre Beck" writes:
  15.  
  16. >Hi,
  17. >
  18. >thanks to all who replied to me regarding my problem
  19. >
  20. > x = (*dat++ << 8) | *dat++;
  21. >
  22. >It turns out to be _ME_ who is dumb in the given case, because I
  23. >didn't know about the subtle issue of sequence points in C. The
  24. >above expression has two evaluations with side effects in one line,
  25.  
  26. That isn't in itself wrong. The problem is that the same variable/object
  27. (in this case dat) is being modified more than once between sequence points.
  28. The following for example is legal:
  29.  
  30.   x = (*p1++ << 8) | *p2++;
  31.  
  32. For a more interesting case consider:
  33.  
  34.   x = ((*p1)++ << 8) | (*p2)++;
  35.  
  36. This is legal only if p1 and p2 point to different objects. So the problem
  37. of determining whether this is legal or not can't always be resolved at
  38. compile time.
  39.  
  40. -- 
  41. -----------------------------------------
  42. Lawrence Kirby | fred@genesis.demon.co.uk
  43. Wilts, England | 70734.126@compuserve.com
  44. -----------------------------------------
  45.